package thread;

public class Demo13 {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(()->{
            //先获取到线程的引用
            Thread currentThread = Thread.currentThread();
            while ((!currentThread.isInterrupted())){
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                     //throw new RuntimeException(e);
                    System.out.println("执行catch操作");
                    break;
                }
            }
        });
        t.start();
        Thread.sleep(3000);
        //在主线程中控制t线程被终止 设置上述标志位
        t.interrupt();
    }
}
